
var SushiSprite = cc.Sprite.extend({
        disappearAction : null,
    type : 1,
    _scale: null,
    onEnter : function() {
            this.addTouchEventListense();
            this._super(); 

            this.disappearAction = this.createDisappearAction();
            this.disappearAction.retain(); 
    },

    onExit : function() {
            this.disappearAction.release();
            this._super();
    },

    //添加点击事件
    addTouchEventListense : function() {
            this.touchListener = cc.EventListener.create({
                    event : cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: this.onTouchBegan,
            });
            cc.eventManager.addListener(this.touchListener, this);
    },

    onTouchBegan : function (touch, event) {
            var pos = touch.getLocation();
            var target = event.getCurrentTarget();
            if (cc.rectContainsPoint(target.getBoundingBox(), pos)) {

                    console.log("touched");
                    return true;
            }
    },

    runDisappear : function(target) { 
            console.log("runDisappear...");

            target.stopAllActions();
            //定义消失动画
            var ac = target.disappearAction;
            var seqAc = cc.Sequence.create(ac, cc.CallFunc.create(function() {
                    console.log("callfun....");

                    if (this.type == 2) {

                            target.getParent().addScore(this._scale);
                    }
                    else if (this.type == 1){

                            target.getParent().addScore(-this._scale);
                    }

                    target.removeFromParent(); 
            }, target));

            target.runAction(seqAc);


    },

    createDisappearAction : function() { 
            var size = cc.winSize;
            var x = cc.random0To1() * size.width;
            var action = cc.MoveTo.create(0.1, cc.p(x, size.height + 30));
            return action;
    },

    removeTouchEventListenser : function(){
            cc.eventManager.removeListener(this.touchListener);
    },

});



